import java.util.Arrays;
import java.util.HashMap;

/**
 * @author wangj881
 * @date 2024-12-24 10:12
 */
public class L1_3 {

    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int target = 9;
        int[] ints = new Solution().twoSum(nums, target);
        System.out.println(Arrays.toString(ints));

    }

    static class Solution {
        public int[] twoSum(int[] nums, int target) {
            HashMap<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < nums.length; i++) {
                Integer index = map.get(target - nums[i]);
                if (index == null) {
                    map.put(nums[i], i);
                } else {
                    return new int[]{index, i};
                }
            }
            return null;
        }
    }

}
